package model

import (
	"context"
	"errors"
	"gateway/chatUtils"

	"gateway/internal/svc"
	"gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CloseSessionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCloseSessionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloseSessionLogic {
	return &CloseSessionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CloseSessionLogic) CloseSession(req *types.SessionReq) error {
	data := chatUtils.GetDataManager(req.SessionId)
	if data != nil {
		data.IsSession = false
		chatUtils.SetDataManager(data)
	} else {
		return errors.New("未查询到会话")
	}
	return nil
}
